import {
    like,
    unlike,
    addFav,
    removeFav,
    commentLike,
    commentUnlike
} from '@/API/api';
export default {
    // 是否喜欢
    ifLike() {
        let {
            details: {
                is_like
            },
            user_id,
            article_id
        } = this
        if (is_like) {
            unlike({
                user_id,
                article_id
            }).then(res => {
                if (res.code == 0) {
                    this.details.is_like = false
                    this.$toast(res.msg)
                    // this.getDetail()
                }
            })
        } else {
            like({
                user_id,
                article_id
            }).then(res => {
                this.details.is_like = true
                this.$toast(res.msg)
                // this.getDetail()
            })
        }

    },
    // 是否收藏
    ifFav() {
        let {
            details: {
                is_fav
            },
            user_id,
            article_id
        } = this
        if (is_fav) {
            removeFav({
                user_id,
                article_id
            }).then(res => {
                if (res.code == 0) {
                    this.details.is_fav = false
                    this.$toast(res.msg)
                    this.getDetail()
                }
            })
        } else {
            addFav({
                user_id,
                article_id
            }).then(res => {
                this.details.is_fav = true
                this.$toast(res.msg)
                this.getDetail()
            })
        }

    },
    CommentLike(item) {
        console.log(item);
        let {
            user_id,
        } = this
        let comment_id = item._id
        console.log(comment_id);
        if (item.is_like) {
            commentUnlike({
                comment_id,
                user_id
            }).then(res => {
                console.log(res);
                this.$toast(res.msg)
                this.getComment()
            })
        } else {
            commentLike({
                comment_id,
                user_id
            }).then(res => {
                this.$toast(res.msg)
                this.getComment()
            })
        }
    }
}